import {
	allAddressData, //全国地区数据
} from '../components/common/addressData'

class getAddressCode {

	getLookUpCode(address) {
			//let address='江苏省宿迁市泗洪县'; //缓存数据
			let province='', provinceCode='', city='', cityCode='',area='',areaCode='';
			for(let i=0;i<allAddressData.value.length;i++){
				if(address.indexOf(allAddressData.value[i].label)>-1){
					provinceCode = allAddressData.value[i].value.split(',')[1]
					province = allAddressData.value[i].value.split(',')[0]
				}
				for(let y=0;y<allAddressData.value[i].children.length;y++){
					if(address.indexOf(allAddressData.value[i].children[y].label)>-1){
				  	cityCode = allAddressData.value[i].children[y].value.split(',')[1]
						city= allAddressData.value[i].children[y].value.split(',')[0]
					}
					for(let n=0;n<allAddressData.value[i].children[y].children.length;n++){
						if(address.indexOf(allAddressData.value[i].children[y].children[n].label)>-1){
							areaCode = allAddressData.value[i].children[y].children[n].value.split(',')[1]
							area = allAddressData.value[i].children[y].children[n].value.split(',')[0]
							break;
						}
					}

				}
			}
			//console.log('省ID',province,provinceCode,'市ID',city,cityCode,'区',area,areaCode)
			// return {
			// 	province:province,
			// 	provinceCode:provinceCode,
			// 	city:city,
			// 	cityCode:cityCode,
			// 	area:area,
			// 	areaCode:areaCode
			// }
			return [`${province},${provinceCode}`,`${city},${cityCode}`,`${area},${areaCode}`]
		}
}
export default new getAddressCode();